<?php
require_once ("db/db_connector.php");
require_once ("db/db_tag.php");
require_once ("db/db_paradise.php");
require_once ("db/db_picture.php");

// Database Access Begins ---------------------------------------- //
$con = get_db_con();
session_start();
if(isset($_SESSION['paradise_list'])){
	unset($_SESSION['paradise_list']);
}
if(isset($_SESSION['tag_list'])){
	unset($_SESSION['tag_list']);
}
if(isset($_SESSION['search_words'])){
	unset($_SESSION['search_words']);
}

	$tag_list = get_tag_list($con);
	$paradise_list = get_all_paradise($con);
	$distinct_tags=array();
	foreach ($tag_list as $tag) {
		$distinct_tags[$tag['name']]=$tag['name'];
		
	}

$_SESSION['paradise_list']=$paradise_list;
$_SESSION['tag_list']=$tag_list;

function cmp($a, $b) {
	return (strcmp($a["type"] . $a["name"], $b["type"] . $b["name"]));
}

usort($tag_list, "cmp");
close_db_con();
// Database Access Ends ------------------------------------------ //
?>

<?php
include_once ("include/header.php");
?>

<div style="float: left">
	
	<form method="post" action="search_result.php">
		<? foreach ($distinct_tags as $tag) :?>
		<input type="checkbox" name="tag_names[]" value=<?=$tag ?> onclick="this.form.submit()" ><?=$tag ?></input>
		</br>		
		<?endforeach ?>
	</form>
	
</div>
<div style="float:right">
	<h2>Paradise Over the World</h2>
	<table>
		<tr>
			<th>thumb_small</th>
			<th>name</th>
		</tr>
		<?php foreach ($paradise_list as $paradise):
		?>
		<tr>
			<td><?php
			if (is_null($paradise["picture_id"]))
				echo "NO ASSIGNED IMAGE";
			else {
				$con = get_db_con();
				$image = get_picture($con, $paradise["picture_id"]);
				echo "<img src=" . $image["thumb_small"] . "/>";
				close_db_con();
			}
			?></td>
			<td><a href="paradise.php?id=<?=$paradise["id"] ?>"> <?=$paradise["name"] ?></a></td>

		</tr>
		<?php endforeach ?>
	</table>
</div>
<?php

include_once ("include/footer.php");
?>